package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    //注入jedispool
    @Autowired
    private JedisPool jedisPool;

    public void clearImg() {
        System.out.println("任务即将执行....");
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        for (String pic : sdiff) {
            QiniuUtils.deleteFileFromQiniu(pic);//删除七牛云上的图片
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, pic);
            System.out.println(pic + "已经被清理....");
        }
    }

}
